package dataproviders;

import items.Stockable;
import java.util.Iterator;
import java.util.List;
import org.apache.wicket.markup.repeater.data.IDataProvider;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;

@SuppressWarnings("serial")
public class StockableDataProvider implements IDataProvider{

	private List<Stockable> stockables;
	
	public StockableDataProvider(List<Stockable> stockables){
		this.stockables = stockables;
	}
	
	@Override
	public void detach() {
		
	}

	@Override
	public Iterator iterator(int first, int count) {
		return this.stockables.subList(first, first + count).iterator();
	}

	@Override
	public int size() {
		return this.stockables.size();
	}

	@Override
	public IModel model(Object object) {
		int index = this.stockables.indexOf(object);
		return new PropertyModel<Stockable>(this.stockables, String.valueOf(index));
	}

	public List<Stockable> getStockables() {
		return stockables;
	}

	public void setStockables(List<Stockable> stockables) {
		this.stockables = stockables;
	}

}
